<?php

namespace App\Http\Controllers\Brand;

use App\Http\Controllers\BaseController;
use App\Models\FirmBrandProfile;
use Illuminate\Http\Request;

class ProfileController extends BaseController
{

    public function show($id)
    {
        $profile = FirmBrandProfile::query()->where('brand_id',$id)->first();

        return $this->success($profile);
    }

    public function store(Request $request)
    {
        $param = $this->validate($request,[
            'brand_id' => 'required',
            'banners' => 'required|array',
            'video_url' => 'max:255',
            'is_invest_price' => 'required|in:1,2',
            'is_join_price' => 'required|in:1,2',
            'start_invest_amount' => 'required_if:is_area_price,2',
            'end_invest_amount' => 'required_if:is_area_price,2',
            'start_join_in_fee' => 'required_if:is_area_price,2',
            'end_join_in_fee' => 'required_if:is_area_price,2',
            'store_num' => 'required',
            'set_up_time' => 'required',
            'cooperation_area' => 'required|array',
            'manage_method' => 'required',
            'invest_crowd' => 'required',
            'tags' => 'required|array',
            'cover_one' => 'required',
            'cover_two' => 'required',
            'intro' => 'string',
            'advantage' => 'string',
            'contact' => 'array'
        ]);

        $profile = FirmBrandProfile::query()->create($param);
        if ($profile->get()){
            return $this->success();
        }

        return  $this->error();
    }

    public function update(Request $request)
    {
        $param = $this->validate($request,[
            'brand_id' => 'required',
            'banners' => 'required|array',
            'video_url' => 'max:255',
            'is_invest_price' => 'required|in:1,2',
            'is_join_price' => 'required|in:1,2',
            'start_invest_amount' => 'required_if:is_area_price,2',
            'end_invest_amount' => 'required_if:is_area_price,2',
            'start_join_in_fee' => 'required_if:is_area_price,2',
            'end_join_in_fee' => 'required_if:is_area_price,2',
            'store_num' => 'required',
            'set_up_time' => 'required',
            'cooperation_area' => 'required|array',
            'manage_method' => 'required',
            'invest_crowd' => 'required',
            'tags' => 'required|array',
            'cover_one' => 'required',
            'cover_two' => 'required',
            'intro' => 'string',
            'advantage' => 'string',
            'contact' => 'array'
        ]);

        $res = FirmBrandProfile::query()->where('brand_id',$param['brand_id'])->update($param);

        if ($res){
            return $this->success();
        }

        return  $this->error();
    }
}
